﻿<!DOCTYPE html>
<!--添加上岗证照-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
</head>
<body>
    <div id="app" v-cloak class="popupW100">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="140px"
                 size="mini">
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <label class="el-form-item__label">{{ContractorPersonnelDirectory.LicenseName+mark.m}}</label>
                        <label class="fl" style="margin: 10px 10px 0 0;">{{Form.LicenseName}}</label>
                        <el-upload name="files" class="fl" ref="Attachmentupload" action="/api/File/UploadFile" multiple="true"
                                   :on-preview="handlePreview" :on-remove="handleRemove"
                                   :before-upload="CoursewareUploadbeforeupload" :on-success="successUpLoad" :auto-upload="true" :limit="1"
                                   :show-file-list="false">
                            <el-button style="margin: 10px;" type="primary" size="mini" @click="btnAttachmentUpload">
                                {{col.btnUpLoad}}
                            </el-button>
                            <!--<el-button type="primary">{{col.btnUpLoad}}</el-button>-->
                        </el-upload>
                    </div>
                </el-col>
                <el-col :span="11">
                    <el-form-item>
                        <div class="elst-select-mini" style="margin-left: -100px">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ContractorPersonnelDirectory.BeginTime+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.BeginTime" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                                                placeholder="选择日期时间">
                                </el-date-picker>
                            </el-input>
                        </div>
                    </el-form-item>
                </el-col>
                <el-col :span="11" :offset="2">
                    <el-form-item>
                        <div class="elst-select-mini" style="margin-left: -100px">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{ContractorPersonnelDirectory.EndTime+mark.m}}
                                </template>
                                <el-date-picker slot="suffix" v-model="Form.EndTime" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                                                placeholder="选择日期时间">
                                </el-date-picker>
                            </el-input>
                        </div>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm()">{{col.btnSave}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
    </div>
    <script type="text/javascript">
        var uploadText = "请选择上传文件";
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                LicenseName: [],
                AttachmentId: '',
                AttachmentName:'',
                CreateTime: '',
                //业务表单内容
                Form: {
                    BeginTime: '',
                    EndTime: '',
                    LicenseName: uploadText,
                },
                formInline: {
                    model: {
                        LicenseName: '',
                    },
                    offset: 0,
                    limit: 10
                },
                IsConsumables: [],
                //表单验证
                rules: {
                    LicenseName: [
                        verification.NotNull,
                    ],
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                handleRemove: function (file) {
                    console.log(file);
                },
                handlePreview: function (file) {
                    console.log(file.name);
                    window.open(file.url)
                },
                //上传附件文件的校验
                CoursewareUploadbeforeupload: function (file) {
                    //var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将附件名赋值到label上
                    this.Form.LicenseName = file.name;
                    const extension = file.type === 'image/jpeg';
                    const extension2 = file.type === 'image/png';
                    const isLt10M = file.size / 1024 / 1024 < 10;
                    if (!extension && !extension2) {
                        this.$message.error('仅可上传 JPG和PNG 格式!');
                    }
                    if (!isLt10M) {
                        this.$message.error('上传图片大小不能超过 10MB!');
                    }
                    //if (extension || extension2 && isLt10M)
                    //    submitUpload(this, 'upload')
                    return extension || extension2 && isLt10M
                },
                successUpLoad: function (res, file) {
                    var data = res.data;//成功后的业务数据
                    var fileModel = data[0];//第一个文件对象
                    var d = new Date();
                    this.CreateTime = new Date(d.setHours(d.getHours() + 8)).toJSON().substr(0, 19).replace('T', ' '),
                    this.AttachmentId = fileModel.id;
                },
                btnAttachmentUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.fileAttachmentUpload != uploadText) {
                        this.$refs.Attachmentupload.clearFiles();
                        this.fileAttachmentUpload = file.name;
                    }
                    else {

                    }
                    this.$refs.Attachmentupload.submit();
                },

                handleChange: function (value) {
                    console.log(value);
                },
                handleChangeA: function (value) {
                    console.log(value);
                },
                //提交数据
                onSubmitForm: function () {
                    parent.app.Form.cbs_user.cbS_UserAttachments.push({
                        //cbSUserId: '',
                        LicenseName: this.Form.LicenseName,
                        beginTime: this.Form.BeginTime,
                        endTime: this.Form.EndTime,
                        //createTime: this.CreateTime,
                        attachmentId: this.AttachmentId,
                        attachmentName: this.Form.LicenseName,
                    });
                    parent.app.ListItem.dialogVisible = false;
                },

            },
            mounted: function () {
                this.id = getUrlParam("id");
                console.log('222', getUrlParam("id"));
            }
        });
    </script>
</body>

</html>